﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WenSkin.Controls
{
    [Serializable]
    public class WenListViewItem : ListViewItem
    {
        public WenListView WenListView = null;
        public WenListViewItem() : base()
        {
        }
        public WenListViewItem(WenListView owner) : base()
        {
            this.WenListView = owner;
        }

        protected WenListViewItem(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) : base(serializationInfo, streamingContext)
        {
        }

        private WenListViewItemCellCollection cells;

        public WenListViewItemCellCollection Cells => cells ??= new WenListViewItemCellCollection(this);

        public class WenListViewItemCell
        {
            public WenListViewItemCell()
            {
            }

            public WenListViewItemCell(string name, object value)
            {
                Name = name;
                Value = value;
            }

            public string Name { get; set; }
            public object Value { get; set; }
            public override string ToString() => Value?.ToString();
        }
        public class WenListViewItemCellCollection : List<WenListViewItemCell>
        {
            private readonly WenListViewItem owner;
            public WenListViewItemCellCollection(WenListViewItem owner)
            {
                this.owner = owner;
            }

            public void Add(string name, object value)
            {
                base.Add(new WenListViewItemCell(name, value));
            }

            public WenListViewItemCell this[string key]
            {
                get => base.Find(q => q.Name.ToUpper() == key.ToUpper());
                set => base.Find(q => q.Name.ToUpper() == key.ToUpper()).Value = value.Value;
            }
        }
    }
}
